<?php

/**
 * 水费假日包车消息模版
 *
 * @author hjc19850430@gmail.com
 */
class CarReserveMsgtpl extends BaseMsgtpl
{
    /**
     * 给用户发消息
     * @param array $orderInfo 订单信息
     */
    public function sendMessageToUser($orderInfo)
    {
        $wechat = D('Wechat')->get($orderInfo['wechat_id']);
        session('account_id', $wechat['account_id']);

        $fans = D('Fans')->get($orderInfo['fans_id'], 'openid,subscribe,wechat_id');

        $url = 'wap.xt.beescrm.com/' . U('base/water/orderList', array('wechat_id' => $orderInfo['wechat_id']));
        if($fans['subscribe']) {

            //由于template_id会根据公众号不同而不同，所以需要在管理后台去设置
            if($wechat['wechat_id'] == 14) {
                $this->wxTplSign = '-wKq2Sg22MBCCCsT_uVwOSOfMm1l0aRtml1vMlWLB88';
            } elseif($wechat['wechat_id'] == 17) {
                $this->wxTplSign = 'ATOvt4E9ucFQACkpS8_l7GTlZVGlVt-PiaEZD7u0-Po';
            }

            $info = array(
                'first' => array("value" => '你已成功购买' . $orderInfo['goods_name'] . '。由于目前寝室调整，导致送水、送机量暴增，您订的水可能会出现延误，我们将尽快送达，造成不便敬请谅解', 'color' => '#173177'),
                'keyword1' => array("value" => $orderInfo['username']),
                'keyword2' => array("value" => $orderInfo['order_price'], "color" => "#173177"),
                'keyword3' => array("value" => date('Y-m-d H:i'), "color" => "#173177"),
                'remark' => array("value" => '详情请登录系统查看'),
            );

            $this->wxObj->messageTpl($wechat['appid'], $wechat['appsecret'], $fans['openid'], $this->wxTplSign, $info, $url);
        }
    }

    /**
     * 给管理员发消息
     * @param array $orderInfo 订单信息
     * @return void
     */
    public function sendMessageToManage($orderInfo)
    {
        $wechat = D('Wechat')->get($orderInfo['wechat_id']);
        session('account_id', $wechat['account_id']);
        
        if($orderInfo['community_name']) {
            //查询后台设置的管理员信息
            $waterManager = D('WaterManager')->getOne(array('address' => $orderInfo['community_name'], 'wechat_id' => $orderInfo['wechat_id'], 'cut_off' => 0));
            if(!$waterManager) {
                $waterManager = D('WaterManager')->getOne(array('address' => '默认', 'wechat_id' => $orderInfo['wechat_id'], 'cut_off' => 0));
            }
        } else {
            $waterManager = D('WaterManager')->getOne(array('address' => '默认', 'wechat_id' => $orderInfo['wechat_id'], 'cut_off' => 0));
        }
        

        if($waterManager)
        {
            $fans = D('Fans')->get($waterManager['fans_id'], 'openid,subscribe,wechat_id');
            
            if($fans['subscribe']) {
                //由于template_id会根据公众号不同而不同，所以需要在管理后台去设置
                $this->wxTplSign = 'ATOvt4E9ucFQACkpS8_l7GTlZVGlVt-PiaEZD7u0-Po';
                
                $info = array(
                    'first' => array("value" => $orderInfo['address'] . '已成功购买' . $orderInfo['goods_name'], 'color' => '#173177'),
                    'keyword1' => array("value" => $orderInfo['username']),
                    'keyword2' => array("value" => $orderInfo['order_price'], "color" => "#173177"),
                    'keyword3' => array("value" => date('Y-m-d H:i'), "color" => "#173177"),
                    'remark' => array("value" => '详情请登录系统查看'),
                );
                $this->wxObj->messageTpl($wechat['appid'], $wechat['appsecret'], $fans['openid'], $this->wxTplSign, $info, '');
            }
        }
    }
    
}
